# -*- coding:utf-8 -*-

'''
PROJECT_NAME : auth_demo
file    : fast
author  : 1032162439@qq.com
date    : 2022-09-12 20:37
IDE     : PyCharm
'''
from fast.service.main import site, FastHandler, get_choice_text
from . import models
from django.shortcuts import HttpResponse
from django import forms



class UserInfoModelForm(forms.ModelForm):
    class Meta:
        model = models.UserInfo
        fields = '__all__'

    def clean_user_name(self):
        user_name = self.cleaned_data['user_name']
        if user_name != 'kobe':
            raise forms.ValidationError('user_name 验证错误')
        return user_name


class HandlerUserInfo(FastHandler):
    list_display = [FastHandler.display_checkbox, 'id', 'user_name', 'mobile', FastHandler.display_edit, FastHandler.display_delete]

    add_model_form_class = UserInfoModelForm

    has_add_btn = True

    per_page_count = 2

    order_list = ['-user_name']

    action_list = [FastHandler.action_multi_delete, ]

    search_list = ['user_name__contains']


class HandlerDepart(FastHandler):

    def get_list_display(self):
        return ['id', 'title']

    def get_order_list(self):
        return ['-id']

    search_list = ['title__contains']

class HandlerPermit(FastHandler):
    list_display = ['id', get_choice_text('权限名', 'permit'), FastHandler.display_edit, FastHandler.display_delete]


site.register(models.UserInfo, HandlerUserInfo)

site.register(models.Depart, HandlerDepart)

site.register(models.Permit, HandlerPermit)
